home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 293_01 / dep.c < prev    next >
C/C++ Source or Header  |  1989-08-23  |  3KB  |  102 lines

  1. /************************** dep.c ****************************
  2.  
  3.                                 */
  4. /*                       Distances.C                        */
  5. /*                 distance shading program                 */
  6.  
  7. /*************************************************************
  8.  
  9.       3-D Reconstruction of Medical Images
  10.  
  11.     Three Dimensional Reconstruction Of Medical
  12.     Images from Serial Slices - CT, MRI, Ultrasound
  13.  
  14.  
  15.    These programs process a set of slices images (scans) for one
  16.    patient. It outputs two sets of files containing nine predefined
  17.    views of bony surfaces. One set contains distance values and
  18.    the other gradient values.
  19.  
  20.    The distance values are used as 3-D spatial topographic surface
  21.    coordinate maps for geometrical analysis of the scanned object.
  22.  
  23.    The gradient values are used for rendering the surface maps on
  24.    CRT displays for subjective viewing where perception of small
  25.    surface details is important.
  26.  
  27.     Daniel Geist, B.S.
  28.     Michael W. Vannier, M.D.
  29.  
  30.     Mallinckrodt Institute of Radiology
  31.     Washington University School of Medicine
  32.     510 S. Kingshighway Blvd.
  33.     St. Louis, Mo. 63110
  34.  
  35.     These programs may be copied and used freely for non-commercial
  36.     purposes by developers with inclusion of this notice.
  37.  
  38.  
  39. ********************************************************************/
  40.  
  41. #include <stdio.h>
  42.  
  43. #define LINE_SIZE 256
  44. #define HEADER_SIZE 512
  45. #define CTLINE_SIZE 512
  46.  
  47. int FIRSTSLICE,LASTSLICE,THRESHOLD; /* some global variables */
  48. int  buffer[LINE_SIZE];
  49. char ybuf[LINE_SIZE];
  50.  
  51. /* input and output files */
  52. char *fnamein="ctbild.000",*fnd="dis.out";
  53.  
  54. /* Set input file name - add number to file extension name*/
  55. setfilename(filenum)
  56. int filenum;
  57. {
  58.     fnamein[7]=filenum/100+'0';
  59.     fnamein[8]=(filenum%100)/10+'0';
  60.     fnamein[9]='0'+filenum%10;
  61. }
  62. create_distance_shades()
  63. {
  64.     int z,x,y;
  65.     FILE *fd,*fn;
  66.     fd=fopen(fnd,"wb");                  /*open output file */
  67.     for(z=0;z<(LASTSLICE-FIRSTSLICE+1);z++){  /* for each slice*/
  68.         setfilename(FIRSTSLICE+z);       /*open slice file */
  69.         fn=fopen(fnamein,"rb");
  70.         fseek(fn,(long)HEADER_SIZE,SEEK_SET);    /* read header    */
  71.         for(y=0;y<LINE_SIZE;y++){           /*for each line */
  72.             fread(buffer,1,CTLINE_SIZE,fn);   /*read line */
  73.             /* find Threshold transition */
  74.             for(x=1;(x<LINE_SIZE) && (buffer[x]<THRESHOLD);x++);
  75.             if(x<LINE_SIZE) ybuf[y]=LINE_SIZE-x;  /* if transition then distance shade */
  76.             else ybuf[y]=0;           /*else empty */
  77.         }
  78.         fclose(fn);              /*close scan file */
  79.         fwrite(ybuf,1,LINE_SIZE,fd);
  80.         printf("did %d \n",z);
  81.     }
  82.     fclose(fd);                /* close output file */
  83. }
  84.  
  85.  
  86. /**********************************************************/
  87. /**** MAIN ***** MAIN ***** MAIN ***** MAIN ***** MAIN ****/
  88. /**********************************************************/
  89. main()
  90. {
  91.     /* first get some parameters from user */
  92.     printf("Enter Starting scan number: ");
  93.     scanf("%d",&FIRSTSLICE);
  94.     printf("Enter ending scan number: ");
  95.     scanf("%d",&LASTSLICE);
  96.     printf("Enter threshold number: ");
  97.     scanf("%d",&THRESHOLD);
  98.     THRESHOLD+=1024;
  99.  
  100.     create_distance_shades();
  101. }
  102.